package com.example.ssmDemo.business.student.service.impl;

import com.example.ssmDemo.core.dto.MyPager;
import com.example.ssmDemo.mybatis.dao.student.StudentMapper;
import com.example.ssmDemo.mybatis.domain.student.StudentDO;
import com.example.ssmDemo.business.student.service.StudentService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 模块名称：
 * 模块类型：
 * 编码人：刘彬
 * 生成时间：2023/2/21
 * 联系电话：
 * */
@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;
    /**
     * 获取学生的所有数据  业务接口层调用实现层方法
     * @return
     */

    @Override
    public StudentDO getStudentByID(String id) {
        StudentDO studentDO=studentMapper.getStudentByID(id);
        System.out.println(studentDO);
        return studentDO;
    }

    @Override
    public MyPager<StudentDO> getStudentPage(MyPager myPager) {
        MyPager<StudentDO> resultPageData=new MyPager<StudentDO>();
        Page<StudentDO> stuPage= PageHelper.startPage(myPager.getPage(), myPager.getSize());
        studentMapper.getStudentPage();
        List<StudentDO> result=stuPage.getResult();
        long total=stuPage.getTotal();
        resultPageData.setTotal(total);
        resultPageData.setRows(result);
        resultPageData.setPage(myPager.getPage());
        resultPageData.setSize(myPager.getSize());
        return resultPageData;
    }

    @Override
    public int insertStudent(StudentDO studentDO) {
        int i=studentMapper.insertStudent(studentDO);
        return i;
    }

    @Override
    public int deleteStudent(String id) {
        int i = studentMapper.deleteStudent(id);
        return i;
    }

    @Override
    public int updateStudent(StudentDO studentDO) {
        int i=studentMapper.updateStudent(studentDO);
        return i;
    }

}
